/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.crm.slcm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Yuwei
 */
@Entity
public class MemberDiscountGroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String discountGroup;
    private Double accSpendingForWs;
    private Double accSpendingForDs;
   
    private Double memberDiscount;
    @OneToMany (targetEntity=Customer.class, cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    private Collection<Customer> customers;
    
    //--------------------------------------------------------------------------
    //                                Constructor
    //--------------------------------------------------------------------------
    public MemberDiscountGroup(){
        discountGroup = "";
        memberDiscount = (double)0;
        customers = new ArrayList<Customer> ();
    }
    
    
    //--------------------------------------------------------------------------
    //                          Getter and Setter
    //--------------------------------------------------------------------------
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Double getMemberDiscount() {
        return memberDiscount;
    }

    public void setMemberDiscount(Double memberDiscount) {
        this.memberDiscount = memberDiscount;
    }
    
    public String getGroup(){
        return this.discountGroup;
    }
    
    public void setGroup(String discountGroup){
        this.discountGroup = discountGroup;
    }
    
    public Collection<Customer> getCustomers(){
        return this.customers;
    }
    
    public void setCustomer(Collection<Customer> customers){
        this.customers = customers;
    }

    public String getDiscountGroup() {
        return discountGroup;
    }

    public void setDiscountGroup(String discountGroup) {
        this.discountGroup = discountGroup;
    }

    public Double getAccSpendingForDs() {
        return accSpendingForDs;
    }

    public void setAccSpendingForDs(Double accSpendingForDs) {
        this.accSpendingForDs = accSpendingForDs;
    }

    public Double getAccSpendingForWs() {
        return accSpendingForWs;
    }

    public void setAccSpendingForWs(Double accSpendingForWs) {
        this.accSpendingForWs = accSpendingForWs;
    }

    
    
    //--------------------------------------------------------------------------
    //                            Entity Methods
    //--------------------------------------------------------------------------
    public void addCustomerToGroup(Customer customer){
        customers.add(customer);
    }
    
    //--------------------------------------------------------------------------
    //                            Object Methods
    //--------------------------------------------------------------------------
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof MemberDiscountGroup)) {
            return false;
        }
        MemberDiscountGroup other = (MemberDiscountGroup) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.crm.slcm.entity.MemberDiscountGroup[ id=" + id + " ]";
    }
    
}
